<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改到岗人员')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-confirm-edit" th:object="${recruitUserConfirm}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">招聘信息：</label>
                <div class="col-sm-8">
                    <select id="recruitId" name="recruitId" class="form-control" th:onchange="selectContent()">
                        <option th:each="info : ${infos}" th:text="${info['recruitName']}" th:value="${info['recruitId']}" th:field="*{recruitId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">招聘内容：</label>
                <div class="col-sm-8">
                    <select id="contentId" name="contentId" class="form-control" th:onchange="selectUser()">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">报名人员：</label>
                <div class="col-sm-8">
                    <select id="userId" name="userId" class="form-control">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">身份证号：</label>
                <div class="col-sm-8">
                    <input name="idCard" th:field="*{idCard}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">到岗日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="confirmTime" class="form-control" placeholder="yyyy-MM-dd" type="text" th:field="*{confirmTime}">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "recruit/confirm";
        $("#form-confirm-edit").validate({
            focusCleanup: true
        });

        $(function (){
            selectContent();
        })

        var contentId = [[${recruitUserConfirm.contentId}]];
        var userId = [[${recruitUserConfirm.userId}]];

        // 根据产品查询规格
        function selectContent() {
            $("#contentId").empty();
            var recruitId = $("#recruitId").val();
            if(recruitId != ''){
                $.ajax({
                    type: "post",
                    url: ctx + "recruit/content/contentList",
                    dataType: "json",
                    data: {"recruitId" : recruitId},
                    success: function(r) {
                        if (r.code == web_status.SUCCESS) {
                            var contentList = r.data;
                            for (var i = 0; i < contentList.length; i++){
                                var content = contentList[i];
                                var html = '';
                                if(content.contentId == contentId){
                                    html = '<option value = "' + content.contentId + '" selected>' + content.postName + "[" + content.postCode + "]" + '</option>';
                                }else{
                                    html = '<option value = "' + content.contentId + '">' + content.postName + "[" + content.postCode + "]" + '</option>';
                                }
                                $("#contentId").append(html);
                            }
                            selectUser();
                        } else {
                            $.modal.msgError(r.msg);
                        }
                        $.modal.closeLoading();
                    }
                });
            }
        }

        // 根据内容查询报名人员
        function selectUser() {
            $("#userId").empty();
            var contentId = $("#contentId").val();
            if(contentId != ''){
                $.ajax({
                    type: "post",
                    url: ctx + "recruit/user/userList",
                    dataType: "json",
                    data: {"contentId" : contentId},
                    success: function(r) {
                        if (r.code == web_status.SUCCESS) {
                            var userList = r.data;
                            for (var i = 0; i < userList.length; i++){
                                var user = userList[i];
                                var html = '';
                                if(user.userId == userId){
                                    html = '<option value = "' + user.userId + '" selected>' + user.name + "[" + user.idCard + "]" + '</option>';
                                }else{
                                    html = '<option value = "' + user.userId + '">' + user.name + "[" + user.idCard + "]" + '</option>';
                                }
                                $("#userId").append(html);
                            }
                        } else {
                            $.modal.msgError(r.msg);
                        }
                        $.modal.closeLoading();
                    }
                });
            }
        }

        $("input[name='confirmTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-confirm-edit').serialize());
            }
        }
    </script>
</body>
</html>